# Maintainer: Jan Alexander Steffens (heftig) <heftig@archlinux.org>
# Contributor: Jan de Groot <jgc@archlinux.org>

pkgbase=freetype2
pkgname=(freetype2 freetype2-demos freetype2-docs)
pkgver=2.13.0
pkgrel=1
pkgdesc="Font rasterization library"
url="https://www.freetype.org/"
arch=(x86_64)
license=(GPL)
# adding harfbuzz for improved OpenType features auto-hinting
# introduces a cycle dep to harfbuzz depending on freetype wanted by upstream
depends=(
  brotli
  bzip2
  harfbuzz
  libpng
  sh
  zlib
)
makedepends=(
  librsvg
  libx11
  meson
  qt5-base
)
source=(
  https://download-mirror.savannah.gnu.org/releases/freetype/freetype-$pkgver.tar.xz{,.sig}
  https://download-mirror.savannah.gnu.org/releases/freetype/freetype-doc-$pkgver.tar.xz{,.sig}
  https://download-mirror.savannah.gnu.org/releases/freetype/ft2demos-$pkgver.tar.xz{,.sig}
  0001-Enable-table-validation-modules.patch
  0002-Enable-subpixel-rendering.patch
  0003-Enable-infinality-subpixel-hinting.patch
  0004-Enable-long-PCF-family-names.patch
  0005-builds-meson-parse_modules_cfg.py-Handle-gxvalid-and.patch
  freetype2.sh
)
sha256sums=('5ee23abd047636c24b2d43c6625dcafc66661d1aca64dec9e0d05df29592624c'
            'SKIP'
            'f6421803442beb5fc74435eb570bea427c8ca763dbf14b4f36caf3145534e9eb'
            'SKIP'
            '4ce8367f9cb9468413c0ea9b3df00c3bb92801418d92a25d157a1ff56e927fcc'
            'SKIP'
            'd279a9d4b2c146722dbc03f9a33009846efe8bbbe3ada52beb4a1aa4d4dfaa38'
            'f2e8a16126723458b413e58da267fb30332d0b42fef972f951e3e9fc081fa492'
            '8e61d12ebdbbcb764a38d4798ee728074bac0aa20978d538b6e7045a63949ab8'
            'cc364cc0ca21b8b30f29d90ab394d82f3303ca7d9813d866e6bf14f9bccd9564'
            '08cf087d7d612b4228e24d74df95cf1f397f7c41054c42837c63c1f33ffaee09'
            'f7f8e09c44f7552c883846e9a6a1efc50377c4932234e74adc4a8ff750606467')
validpgpkeys=(E30674707856409FF1948010BE6C3AAC63AD8E3F) # Werner Lemberg <wl@gnu.org>

prepare() {
  ln -sr freetype-$pkgver ft2demos-$pkgver/subprojects/freetype2

  cd freetype-$pkgver
  patch -Np1 -i ../0001-Enable-table-validation-modules.patch
  patch -Np1 -i ../0002-Enable-subpixel-rendering.patch
  patch -Np1 -i ../0003-Enable-infinality-subpixel-hinting.patch
  patch -Np1 -i ../0004-Enable-long-PCF-family-names.patch
  patch -Np1 -i ../0005-builds-meson-parse_modules_cfg.py-Handle-gxvalid-and.patch
}

build() {
  local meson_options=(
    -D freetype2:default_library=shared
  )

  arch-meson ft2demos-$pkgver build "${meson_options[@]}"
  meson compile -C build
}

check() {
  meson test -C build --print-errorlogs
}

_pick() {
  local p="$1" f d; shift
  for f; do
    d="$srcdir/$p/${f#$pkgdir/}"
    mkdir -p "$(dirname "$d")"
    mv "$f" "$d"
    rmdir -p --ignore-fail-on-non-empty "$(dirname "$f")"
  done
}

package_freetype2() {
  provides=(libfreetype.so)
  install=freetype2.install
  backup=(etc/profile.d/freetype2.sh)

  meson install -C build --destdir="$pkgdir"
  install -Dt "$pkgdir/etc/profile.d" -m644 freetype2.sh
  install -Dt "$pkgdir/usr/share/aclocal" -m644 \
    freetype-$pkgver/builds/unix/freetype2.m4

  _pick demos "$pkgdir"/usr/bin
  _pick demos "$pkgdir"/usr/share/man/man1
}

package_freetype2-demos() {
  pkgdesc="Freetype tools and demos"
  depends=(freetype2 libx11 librsvg)
  optdepends=('qt5-base: ftinspect')
  mv demos/* "$pkgdir"
}

package_freetype2-docs() {
  pkgdesc="Freetype documentation"
  depends=(freetype2)

  mkdir -p "${pkgdir}/usr/share/doc"
  cp -r freetype-$pkgver/docs "$pkgdir/usr/share/doc/$pkgbase"
}

# vim:set sw=2 sts=-1 et:
